// Schedule Sorter Algorithm
// Coded by: Darren and Bryan
// Versions
// 1.0 - Initial version
//		*compiles with no errors -- is as-yet untested
//		*constraint test needs to be implemented in slotFunction() function

#include "course.h"
#include "schedule.h"

/// Gets the 2 vector timings and compares them.
/// \return true - conflict;  false - no conflict.
bool findConflict(std::vector<int>, std::vector<int>);

/// Compares the timings for two independent courseSection objects.
/// calls findConflict() function.
/// \return  true - conflict exists;  false - no conflict.
bool courseSecCompare(std::vector<CourseSection*>, std::vector<CourseSection*>);

// Uses the boost::weak_ptr in the courseSection object to getthe entire sequence from the leaf node
// returns a vector containing the entire sequence for a given node, to be used by slotConflict() function
std::vector<CourseSection*> getSeqFromLeafNode(CourseSection*);

/// Compares the timings for all the courseSections of one "slot".
/// Calls courseSecCompare() function.
/// \return true - conflict exists;  false - no conflict.
bool slotConflict(std::vector<CourseSection*> slot);

/// Recursive function that takes a leaf node and gets a vector of all the
/// coursesection pointers in that sequence using the reverse weak_ptr in the
/// courseSection class.  Function is used later in the scheduleSorter function.
/// \param sectionRef leaf node.
/// \param leafListRef The sequence is returned here.  Should be empty when
/// calling fuction.
void leafRecursion(CourseSection* sectionRef, std::vector<CourseSection*> &leafListRef);

/// Gets the actual courseSection objects from the courseSection pointers in
/// order to build the Schedule object.  Note:  should we change the Schedule
/// object to contain a vector of CourseSection pointers instead ob objects?
/// Function is used laster in the slotFunction() function
/// \param sectionPointers Vector of pointers to convert.
/// \param sections Provide an empty vector of CourseSection objects for
/// the conversion.
void getSectionsFromPointers(std::vector<CourseSection*> sectionPointers, std::vector<CourseSection> &sections);

/// Compute all "slots" (combinationms of courseSection objects).  Calls the
/// slotConflict() function to test each "slot" for timing conflicts.  Then it
/// will test against user constraints.  If the slot is good, it will create a
/// Schedule object with it and insert it into the vector of schedules.
void slotFunction(std::vector<std::vector<CourseSection*> >::iterator, std::vector<std::vector<CourseSection*> >::iterator, std::vector<std::vector<CourseSection*> >::iterator, std::vector<CourseSection*>, std::vector<Schedule>&);

/// Master function;  generates valid schedules for the given courses.
/// Provide a vector of course pointers and an empty vector of Schedule
/// objects.  If the function exits and the size of the vector has not changed,
/// no valid schedules are present for these courses and the current
/// constraints.
void scheduleSorter(std::vector<Course*>, std::vector<Schedule>&, int sem);
